import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import * as echarts from 'echarts'  //echarts 引用使用断言，否则可能报错
import 'element-ui/lib/theme-chalk/index.css';
import axios from "axios";
import dataV from '@jiaminghi/data-view'
Vue.use(dataV)
Vue.prototype.$echarts=echarts
Vue.config.productionTip = false
Vue.use(ElementUI);
new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
axios.interceptors.request.use(config => {
  // 1.从缓存中获取到token,这里的Authorization时登录时你给用户设置token的键值
  let authorization = localStorage.getItem("token");
  console.log(authorization+"我的")
  config.withCredentials=true;
  config.headers["Content-Type"]="application/x-www-form-urlencoded";
  // 2.如果token不为null，那么设置到请求头中，此处哪怕为null，我们也不进行处理，因为后台会进行拦截
  if (authorization) {
    //后台给登录用户设置的token的键时什么，headers['''']里的键也应该保持一致
    config.headers['token'] = authorization;
  }
  // 3.放行
  return config;
}, error => {
//失败后抛出错误
  Promise.reject(error);
})

